<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/10/18
 * Time: 8:27
 */
namespace app\api\controller;
use think\Db;
use think\Request;
use app\api\model\Hotel as HotelStore;
use app\common\model\HotelModel as h;
class Hotel extends Nocommon
{
    /*
     * 酒店列表
     */
    public function hotelList()
    {
        if(Request::instance()->isPost()){
            $type = input('type','1','trim');
            $sort = input('sort','1','trim');
            $content = input('content','','trim');

            $where['hotel_name'] = array('like','%' . $content . '%');

            $post = input('param.');
            $page = $this->p();
            $hot = new HotelStore();
            //按销量排序
            if($type==1 && $sort==1){
                $hotels = $hot->hotel_list($where,$page,1,$post['longitude'],$post['latitude']);
            }
            if($type==2 && $sort==1){
                $where['kind_type'] = array('like','%'. 1 .'%');
                $hotels = $hot->hotel_list($where,$page,1,$post['longitude'],$post['latitude']);
            }
            if($type==3 && $sort==1){
                $where['kind_type'] = array('like','%'. 2 . '%');
                $hotels = $hot->hotel_list($where,$page,1,$post['longitude'],$post['latitude']);
            }
            if($type==4 && $sort==1){
                $where['kind_type'] = array('like','%'. 3 . '%');
                $hotels = $hot->hotel_list($where,$page,1,$post['longitude'],$post['latitude']);
            }
            //按价格排序
            if($type==1 && $sort==2){
                $hotels = $hot->hotel_list($where,$page,2,$post['longitude'],$post['latitude']);
            }
            if($type==2 && $sort==2){
                $where['kind_type'] = array('like','%'. 1 .'%');
                $hotels = $hot->hotel_list($where,$page,2,$post['longitude'],$post['latitude']);
            }
            if($type==3 && $sort==2){
                $where['kind_type'] = array('like','%'. 2 . '%');
                $hotels = $hot->hotel_list($where,$page,2,$post['longitude'],$post['latitude']);
            }
            if($type==4 && $sort==2){
                $where['kind_type'] = array('like','%'. 3 . '%');
                $hotels = $hot->hotel_list($where,$page,2,$post['longitude'],$post['latitude']);
            }
            //按好评排序
            if($type==1 && $sort==3){
                $hotels = $hot->hotel_list($where,$page,3,$post['longitude'],$post['latitude']);
            }
            if($type==2 && $sort==3){
                $where['kind_type'] = array('like','%'. 1 .'%');
                $hotels = $hot->hotel_list($where,$page,3,$post['longitude'],$post['latitude']);
            }
            if($type==3 && $sort==3){
                $where['kind_type'] = array('like','%'. 2 . '%');
                $hotels = $hot->hotel_list($where,$page,3,$post['longitude'],$post['latitude']);
            }
            if($type==4 && $sort==3){
                $where['kind_type'] = array('like','%'. 3 . '%');
                $hotels = $hot->hotel_list($where,$page,3,$post['longitude'],$post['latitude']);
            }
            //距离排序
            if($type==1 && $sort==4){
                $hotels = $hot->hotel_list($where,$page,4,$post['longitude'],$post['latitude']);
            }
            if($type==2 && $sort==4){
                $where['kind_type'] = array('like','%'. 1 .'%');
                $hotels = $hot->hotel_list($where,$page,4,$post['longitude'],$post['latitude']);
            }
            if($type==3 && $sort==4){
                $where['kind_type'] = array('like','%'. 2 . '%');
                $hotels = $hot->hotel_list($where,$page,4,$post['longitude'],$post['latitude']);
            }
            if($type==4 && $sort==4){
                $where['kind_type'] = array('like','%'. 3 . '%');
                $hotels = $hot->hotel_list($where,$page,4,$post['longitude'],$post['latitude']);
            }
            return $this->apiReturn('200','成功',$hotels);
        }
    }
 
      /**
     * [getTourInfo 获取酒店的详情]
     * @Author   kendy
     * @DateTime 2019-10-31T10:06:35+0800
     * @return   [type]                   [description]
     */
    public function getHotelInfo()
    {
         if(Request::instance()->isPost()){  
          $hot = new HotelStore();
          $hotel_id = input('post.hotel_id/d');
          $page = $this->p();    
          $limit = input('post.limit/d');
          if(empty($hotel_id))  return $this->apiReturn('400','酒店id为空',0);
          $hotInfo = $hot->getHotelInfo($hotel_id);  
          return $this->apiReturn('200','成功',$hotInfo);
        } 
    }
    
    /**
     * [HotelReserve 酒店预定页面]
     * @Author   kendy
     * @DateTime 2019-11-08T10:14:09+0800
     */
    public function HotelReserve()
    {
      if(Request::instance()->isPost()){  
        $room_id = (int)input('post.room_id');
        if(empty($room_id)) return $this->apiReturn('400','房间id为空',0);
        $hot = new h();
        $hotInfo = $hot->getHotelReserveInfo($room_id);  
         return $this->apiReturn('200','成功',$hotInfo); 
       } 


    }

}